package com.ai.config;

import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RequiredArgsConstructor
public class ChatConfig {

    private final VectorStore vectorStore;

    @Bean
    public ChatClient chatClient(OllamaChatModel ollamaChatModel, ChatMemory redisChatMemory) {
        return ChatClient.builder(ollamaChatModel)
                .defaultSystem("你是一个智能助手。能帮助用户解决各种问题，你很有礼貌，回答问题条理清晰。你的首选语言是中文。")

                .defaultAdvisors(
                        MessageChatMemoryAdvisor.builder(redisChatMemory).build()// chat-memory advisor
                        //,QuestionAnswerAdvisor.builder(vectorStore).build() // RAG advisor
                )
                // 工具有bug 会导致流式输出失效
                //.defaultTools(new DateTimeTools())
                .build();
    }

}
